//
//  LeftMenuViewController.m
//  SuiRan
//
//  Created by lanou3g on 15-5-1.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "LeftMenuViewController.h"
#import "RadioCollectionViewController.h"
#import "UIViewController+RESideMenu.h"
#import "RESideMenu.h"
#import "ReadCollectionViewController.h"
#import "SetTableViewController.h"
#import "GroupViewController.h"



@interface LeftMenuViewController ()
@property (retain, readwrite, nonatomic) UITableView *tableView;
@property (nonatomic, retain) UIView *darkView;

@property (nonatomic, retain) UIView *darkView2;

@end

@implementation LeftMenuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView = ({
        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(60, (self.view.frame.size.height - 60 * 4) / 2.0f, self.view.frame.size.width, 60 * 4) style:UITableViewStylePlain];
        tableView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.opaque = NO;
        tableView.backgroundColor = [UIColor clearColor];
        tableView.backgroundView = nil;
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        tableView.bounces = NO;
        tableView;
    });
    [self.view addSubview:self.tableView];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
#pragma mark - 初始化RadioCollectionViewController
    UICollectionViewFlowLayout *flowLayout = [UICollectionViewFlowLayout new];
    flowLayout.itemSize = CGSizeMake(110.0 / 375 * kScreenWidth, 123.0 / 667 * kScreenHeight);//每个Item的大小
    flowLayout.minimumInteritemSpacing = 10.0 / 375 * kScreenWidth;//最小列间距
    flowLayout.minimumLineSpacing = 20.0 / 667 * kScreenHeight;//最小行间距
    flowLayout.headerReferenceSize = CGSizeMake(0, 30.0 / 667 * kScreenHeight);//头区大小
    flowLayout.footerReferenceSize = CGSizeMake(0, 10.0 / 667 * kScreenHeight);//尾区大小
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;//滚动方向(横向滚动和竖向滚动)
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 10.0 / 667 * kScreenHeight, 0, 10.0 / 667 * kScreenHeight);//修改距离左边和右边的值

  
    
    // 创建系统自带的布局对象（阅读）
    UICollectionViewFlowLayout *flowLayout1 = [UICollectionViewFlowLayout new];
    
    flowLayout1.itemSize = CGSizeMake(320 / 375.0 *  kScreenWidth, 200 / 667.0 *kScreenHeight);
    flowLayout1.minimumLineSpacing = 5 / 667.0 *kScreenHeight; // 设置最小行间距
    flowLayout1.minimumInteritemSpacing = 5 / 375.0 *kScreenWidth; // 设置最小列间距
    flowLayout1.headerReferenceSize = CGSizeMake(0, 20 / 667.0 *kScreenHeight); // 头区大小
    flowLayout1.footerReferenceSize = CGSizeMake(0, 20 / 667.0 *kScreenHeight); // 尾区大小
    
    flowLayout1.sectionInset = UIEdgeInsetsMake(0, 20 / 667.0 *kScreenWidth, 0, 20 / 667.0 *kScreenWidth);
    
    self.navigationItem.title = @"阅读";

    // 创建社区页面
    GroupViewController *gVC = [[GroupViewController new] autorelease];
    UINavigationController *GroupNC = [[[UINavigationController alloc] initWithRootViewController:gVC] autorelease];
    
    
    
// 创建设置页面
    SetTableViewController *sTVC = [[SetTableViewController new] autorelease];
    UINavigationController *nc = [[[UINavigationController alloc] initWithRootViewController:sTVC] autorelease];
    

    
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
        case 0:
            
            [self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[[RadioCollectionViewController alloc] initWithCollectionViewLayout:flowLayout]]
                                                         animated:YES];
            [self.sideMenuViewController hideMenuViewController];
            break;
        case 1:
            [self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[[ReadCollectionViewController alloc] initWithCollectionViewLayout:flowLayout1]]
                                                         animated:YES];
            [self.sideMenuViewController hideMenuViewController];
            break;
        case 2:
            [self.sideMenuViewController setContentViewController:GroupNC animated:YES];
            [self.sideMenuViewController hideMenuViewController];
            break;
            
        case 3:
            [self.sideMenuViewController setContentViewController:nc animated:YES];
            [self.sideMenuViewController hideMenuViewController];
            break;
        default:
            break;
    }
}


#pragma mark -
#pragma mark UITableView Datasource

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60. / 667 *kScreenHeight;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex
{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.backgroundColor = [UIColor clearColor];
        cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:21];
        cell.textLabel.textColor = [UIColor blackColor];
        cell.textLabel.highlightedTextColor = [UIColor lightGrayColor];
        cell.selectedBackgroundView = [[UIView alloc] init];
    }
    
    NSArray *titles = @[@"电  台", @"阅  读", @"社  区", @"设  置"];

    cell.textLabel.text = titles[indexPath.row];
    cell.textLabel.font = [UIFont fontWithName:@"Optima" size:20];
    cell.textLabel.textColor = [UIColor colorWithWhite:0.200 alpha:1.000];

    return cell;
}

- (void)dealloc
{
    [_tableView release];
    [super dealloc];
}
@end
